
exports.GACommonUtils = Core.Class.singleton ({

	initialize: function() {
        this._orientation = Device.OrientationEmitter.Orientation.Portrait;//NgApplicationOrientation.LandscapeLeft;	
	},
	
	getKeyForStoreObject: function(storeObject) {
		if (storeObject != null) {
			if (storeObject.objectType == "item") {
				var key = [];
				key.push(storeObject.parent.parent.visible_id);
				key.push(storeObject.parent.visible_id);
				key.push(storeObject.visible_id);
				return key.join("_");
			}
			else if (storeObject.objectType == "cat") {
				var key = [];
				key.push(storeObject.parent.visible_id);				
				key.push(storeObject.visible_id);
				return key.join("_");
			}
			else {
				return storeObject.visible_id;
			}
		}
		return null;
	},
	
	getBuyPrice: function(storeObject, currencyName) {
		if (storeObject != null) {
			var prices = storeObject.buy_prices;
			if (typeof prices != 'undefined') {
				var activeBucket = storeObject.active_bucket;
				var priceForBucket = prices[activeBucket];
				if (typeof priceForBucket != 'undefined') {
					if (typeof currencyName != 'undefined' && currencyName != null) {
						var value = priceForBucket[currencyName];
						if (typeof value != 'undefined') {
							return value;
						}
					}
					else {
						return priceForBucket;
					}
				}
			}
		}
		return null;
	},

	getSellPrice: function(storeObject, currencyName) {
		if (storeObject != null) {
			var sellPrice = storeObject.sell_prices;
			if (typeof sellPrice != 'undefined') {
				if (typeof currencyName != 'undefined' && currencyName != null) {
					var value = sellPrice[currencyName];
					if (typeof value != 'undefined') {
						return value;
					}
				}
				else {
					return sellPrice;
				}
			}
		}
		return null;
	},

	isDeviceSupported: function(deviceName, textureFormat) {
		if(textureFormat == 'pvr') {
			
			var supportedDevices = GAGameLoader.getResponseObject().getCustomAttributes();
			NgLogE("Sunilla:: "+ supportedDevices.SD_NAMES);
			var sdNames = supportedDevices['SD_NAMES'];
			var deviceNames = sdNames.split("|") , i = 0 , len = deviceNames.length;
			
			for(; i < len ; i++)
			{
				NgLogE("Sunilla:: len  "+len +" "+ deviceNames[i] +  " == "+ deviceName);
				if(deviceNames[i] == deviceName)
				{
					return true;
				}
			}
		}
		return false;

	},

	getServerParams: function() {
		var params = {};
		params[GA_UDID_PARAM_KEY] = GAConfigurations.getUdid();
		params[GA_DEVICE_TYPE_PARAM_KEY] = GAConfigurations.getDeviceType();
		params[GA_DEVICE_OS_PARAM_KEY] = GAConfigurations.getOsVersion();
		params[GA_GAME_VERSION_PARAM_KEY] = GAConfigurations.getGameVersion();
		params[GA_GAME_NAME_PARAM_KEY] = GAGameLoader.getResponseObject().getGame();
		//params[GA_DEVICE_GENERATION_PARAM_KEY] = GAConfigurations.
		return params;
	},
	
	getScreenWidth: function() {
		return (this._orientation ==  Device.OrientationEmitter.Orientation.Portrait || this._orientation == Device.OrientationEmitter.Orientation.PortraitUpsideDown) ? Core.Capabilities.getScreenWidth() : Core.Capabilities.getScreenHeight();
        //return (this._orientation == NgApplicationOrientation.Portrait || this._orientation == NgApplicationOrientation.PortraitUpsideDown) ? Core.Capabilities.getScreenWidth() : Core.Capabilities.getScreenHeight();
    },

    getScreenHeight: function() {
    	return (this._orientation ==  Device.OrientationEmitter.Orientation.Portrait || this._orientation == Device.OrientationEmitter.Orientation.PortraitUpsideDown) ? Core.Capabilities.getScreenHeight() : Core.Capabilities.getScreenWidth();
        //return (this._orientation == NgApplicationOrientation.Portrait || this._orientation == NgApplicationOrientation.PortraitUpsideDown) ? Core.Capabilities.getScreenHeight() : Core.Capabilities.getScreenWidth();
    },

	/*getAdjustedX: function(x) {
   		
   		var width = 0 , newWidth = 0 ;
   		width = this.getScreenWidth();
   		newWidth = (width / 320) * x;
   		
       	return newWidth;
   		
   },
    
   getAdjustedY: function(y) 
   {
   		var height = 0 , newHeight = 0;
		height = this.getScreenHeight();
		newHeight = (height / 480) * y;
      
       return newHeight;
   },*/
    
    getAdjustedX: function(x) {
        return (x / aspectRatioFactor.x) * this.getScreenWidth();
    },

    getAdjustedY: function(y) {
        return (y / aspectRatioFactor.y) * this.getScreenHeight();
    },
    
	adjustWidthWithDevice: function(aWidth)
	{
		var w = 0, calWidth = 0;
		w = this.getScreenWidth();
		calWidth = aWidth * (w/320);
		return calWidth;			
	},
	adjustHeightWithDevice: function(aHeight)
	{
		var h = 0 , calHeight = 0;
		h = this.getScreenHeight();
		calHeight = aHeight * (h/480);
		return calHeight;		
		
	},
	
    setApplicationOrientation: function(orientation) {
		Device.OrientationEmitter.setInterfaceOrientation(orientation);
        //NgApplication.getInstance().setOrientation(orientation);
        this._orientation = orientation;
    },
	
	getAdjustedFontSize: function(fieldHeight) {
		if(Core.Capabilities.getDeviceName() == "DROID PRO")
		{
			return (this.getAdjustedY(fieldHeight / 2) / aspectRatioFactor.d)*4/3;
		}
		else if(Core.Capabilities.getDeviceName() == "i386")//for ios simulator 
		{
			return (this.getAdjustedY(fieldHeight / 2) / aspectRatioFactor.d)*8/7;
		}	
			
        return this.getAdjustedY(fieldHeight / 2) / aspectRatioFactor.d;
    }
	
});